from pythonds.sort import *


def test():
    import random, time

    alist = [54, 29, 93, 17, 77, 31, 44, 55, 20, 44]
    print("验证排序的正确性")
    print("原始列表：", alist)

    t = alist.copy()
    violence_sort(t)
    print("暴力排序：", t)

    t = alist.copy()
    bubble_sort(t)
    print("冒泡排序：", t)

    t = alist.copy()
    short_bubble_sort(t)
    print("快速冒泡：", t)

    t = alist.copy()
    selection_sort(t)
    print("选择排序：", t)

    t = alist.copy()
    insertion_sort(t)
    print("插入排序：", t)

    t = alist.copy()
    shell_sort(t)
    print("希尔排序：", t)

    t = alist.copy()
    merge_sort(t)
    print("归并排序：", t)

    t = alist.copy()
    merge_em_sort(t)
    print("改进归并：", t)

    t = alist.copy()
    merge_nr_sort(t)
    print("循环归并：", t)

    t = alist.copy()
    quick_sort(t)
    print("快速排序：", t)

    t = alist.copy()
    t = sorted(t)
    print("内置排序：", t)

    print("-" * 60)
    print("验证排序的时间复杂度")
    alist = [random.randint(0, 50000) for _ in range(10000)]

    # t = alist.copy()
    # st = time.time_ns()
    # violence_sort(t)
    # et = time.time_ns()
    # print("暴力排序用时:%d 毫秒" % ((et - st) // 1000000))

    # t = alist.copy()
    # st = time.time_ns()
    # bubble_sort(t)
    # et = time.time_ns()
    # print("冒泡排序用时:%d 毫秒" % ((et - st) // 1000000))

    # t = alist.copy()
    # st = time.time_ns()
    # short_bubble_sort(t)
    # et = time.time_ns()
    # print("快速冒泡用时:%d 毫秒" % ((et - st) // 1000000))

    # t = alist.copy()
    # st = time.time_ns()
    # selection_sort(t)
    # et = time.time_ns()
    # print("选择排序用时:%d 毫秒" % ((et - st) // 1000000))

    # t = alist.copy()
    # st = time.time_ns()
    # insertion_sort(t)
    # et = time.time_ns()
    # print("插入排序用时:%d 毫秒" % ((et - st) // 1000000))

    t = alist.copy()
    st = time.time_ns()
    shell_sort(t)
    et = time.time_ns()
    print("希尔排序用时:%d 毫秒" % ((et - st) // 1000000))

    t = alist.copy()
    st = time.time_ns()
    merge_sort(t)
    et = time.time_ns()
    print("归并排序用时:%d 毫秒" % ((et - st) // 1000000))

    t = alist.copy()
    st = time.time_ns()
    merge_em_sort(t)
    et = time.time_ns()
    print("改进归并用时:%d 毫秒" % ((et - st) // 1000000))

    t = alist.copy()
    st = time.time_ns()
    merge_nr_sort(t)
    et = time.time_ns()
    print("循环归并用时:%d 毫秒" % ((et - st) // 1000000))

    t = alist.copy()
    st = time.time_ns()
    quick_sort(t)
    et = time.time_ns()
    print("快速排序用时:%d 毫秒" % ((et - st) // 1000000))

    t = alist.copy()
    st = time.time_ns()
    sorted(t)
    et = time.time_ns()
    print("内置排序用时:%d 毫秒" % ((et - st) // 1000000))
